package com.beidouin.GnssMain.models;

/**
 * Created by flyingfluff on 2016/10/5.
 */

import android.location.GpsSatellite;

public class GnssSatellite {
    public static final int SATE_GPS = 0;
    public static final int SATE_GLONASS = 1;
    public static final int SATE_GALILEO = 2;
    public static final int SATE_BEIDOU = 3;
    public static final int SATE_QZSS = 4;
    public static final int SATE_OTHER = 5;
    public static final int SATE_TOTAL = 6;

    public static final int SATE_ID_GPS_START = 1;
    public static final int SATE_ID_GPS_LAST = 54;
    public static final int SATE_ID_GLONASS_START = 65;
    public static final int SATE_ID_GLONASS_LAST = 96;
    public static final int SATE_ID_GALILEO_START = 101;
    public static final int SATE_ID_GALILEO_LAST = 130;
    public static final int SATE_ID_GALILEO_START2 = 301;
    public static final int SATE_ID_GALILEO_LAST2 = 330;
    public static final int SATE_ID_QZSS_START = 193;
    public static final int SATE_ID_QZSS_LAST = 200;
    public static final int SATE_ID_BEIDOU_START = 201;
    public static final int SATE_ID_BEIDOU_LAST = 235;//235

    public static final int nullPrn = 0xffff;

    boolean mUsedInFix;
    int mPrn;
    int mPrn1Based;
    float mSnr;
    float mElevation;
    float mAzimuth;
    int sateType;

    public GnssSatellite() {
        mUsedInFix = false;
        mPrn = nullPrn;
    }
    public int getPrn() {
        return mPrn;
    }

    public int getPrn1Based() {
        return mPrn1Based;
    }

    public void setPrn(int prn) {
        mPrn = prn;

        if (prn >= SATE_ID_GPS_START && prn <= SATE_ID_GPS_LAST) {
            sateType = SATE_GPS;
            mPrn1Based = mPrn - SATE_ID_GPS_START + 1;
        } else if (prn >= SATE_ID_GLONASS_START && prn <= SATE_ID_GLONASS_LAST) {
            sateType = SATE_GLONASS;
            mPrn1Based = mPrn - SATE_ID_GLONASS_START + 1;
        } else if (prn >= SATE_ID_GALILEO_START && prn <= SATE_ID_GALILEO_LAST) {
            sateType = SATE_GALILEO;
            mPrn1Based = mPrn - SATE_ID_GALILEO_START + 1;
        } else if (prn >= SATE_ID_GALILEO_START2 && prn <= SATE_ID_GALILEO_LAST2) {
            sateType = SATE_GALILEO;
            mPrn1Based = mPrn - SATE_ID_GALILEO_START2 + 1;
        } else if (prn >= SATE_ID_QZSS_START && prn <= SATE_ID_QZSS_LAST){
            sateType = SATE_QZSS;
            mPrn1Based = mPrn - SATE_ID_QZSS_START + 1;
        } else if (prn >= SATE_ID_BEIDOU_START && prn <= SATE_ID_BEIDOU_LAST) {
            sateType = SATE_BEIDOU;
            mPrn1Based = mPrn - SATE_ID_BEIDOU_START + 1;
        } else {
            sateType = SATE_OTHER;
            mPrn1Based = mPrn;
        }
    }

    public int getType() { return sateType; }

    public float getSnr() {
        return mSnr;
    }
    public void setSnr(float snr) {
        mSnr = snr;
    }

    public float getElevation() {
        return mElevation;
    }
    public void setElevation(float ele) { mElevation = ele; }

    public float getAzimuth() {
        return mAzimuth;
    }
    public void setAzimuth(float azi) { mAzimuth = azi; }

    public boolean isUsedInFix() {
        return mUsedInFix;
    }
    public void setUsedInFix(boolean bUsed) { mUsedInFix = bUsed; }

    public static GnssSatellite copyValue(GpsSatellite sate) {
        GnssSatellite newSate = new GnssSatellite();
        newSate.setUsedInFix(sate.usedInFix());
        newSate.setPrn(sate.getPrn());
        newSate.setSnr(sate.getSnr());
        newSate.setElevation(sate.getElevation());
        newSate.setAzimuth(sate.getAzimuth());
        return newSate;
    }

}
